public class CasketOfStarEasy {

	private int[] remove(int[] array, int i) {
		int[] a = new int[array.length - 1];
		int count = 0;
		for (int j = 0; j < array.length; j++) {
			if (j == i)
				continue;
			a[count++] = array[j];
		}
		return a;
	}

	public int maxEnergy(int[] weight) {
		if (weight.length == 3) {
			return weight[0] * weight[2];
		} else {
			int max = 0;
			for (int i = 1; i < weight.length - 1; i++) {
				int energy = weight[i - 1] * weight[i + 1]
						+ maxEnergy(remove(weight, i));
				if (max < energy) {
					max = energy;
				}
			}
			return max;
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		CasketOfStarEasy c = new CasketOfStarEasy();
		int[] weight = { 1, 2, 3, 4 };
		System.out.println(c.maxEnergy(weight));
	}

}
